// https://nuxt.com/docs/api/configuration/nuxt-config
import { EnvConfig } from './env.config'
import { useNuxtHead, useNuxtI18nConfig, useRouteRules } from './useNuxtConfig'

const { i18nConfig, DEFAULT_LOCALE, LANGUAGES, LANGUAGES_I18N } = useNuxtI18nConfig()
const { devRouteRules, prodRouteRules } = useRouteRules()
export default defineNuxtConfig({
  devtools: { enabled: false },
  modules: [
    '@nuxtjs/i18n',
    'nuxt-vue3-google-signin',
    '@nuxtjs/robots',
    '@nuxt/image',
    '@pinia/nuxt',
    '@vant/nuxt',
    'nuxt-vitalizer',
    '@vueuse/nuxt',
  ],
  vitalizer: {
    delayHydration: {
      hydrateOnEvents: ['mousemove', 'scroll', 'keydown', 'click', 'touchstart', 'wheel'],
      idleCallbackTimeout: 8000,
      postIdleTimeout: 4000,
    },
  },
  vant: {},

  googleSignIn: {
    clientId: '44249926361-uie15hged34sae3vk5adopjp23dvdd0e.apps.googleusercontent.com',
  },

  css: ['~/assets/css/main.css'],
  components: true,
  i18n: i18nConfig as any,

  robots: {
    rules: [
      { UserAgent: '*' },
      { Disallow: '/pre-order*' },
      { Disallow: '/*/pre-order*' },
      { Disallow: '/common/*' },
      { Disallow: '/*/common/*' },
      { Disallow: '/sso/*' },
      { Disallow: '/*/sso/*' },
      { Disallow: '/user/*' },
      { Disallow: '/*/user/*' },
      { Disallow: '/cdn-fpw/sxg/' },
      { Disallow: '/cdn-cgi/zaraz/' },
      //@ts-ignore
      // { 'Clean-param': 'redirectTo&refresh&goodsSkuId&count' },
      { BlankLine: true },
      { Sitemap: `https://bittopup.com/sitemap.xml` },
      { Sitemap: `https://bittopup.com/goods-sitemap.xml` },
      { Sitemap: `https://bittopup.com/goods-sitemap-hi.xml` },
      { Sitemap: `https://bittopup.com/goods-sitemap-id.xml` },
      { Sitemap: `https://bittopup.com/goods-sitemap-ko.xml` },
      { Sitemap: `https://bittopup.com/goods-sitemap-ms.xml` },
      { Sitemap: `https://bittopup.com/goods-sitemap-es.xml` },
      { Sitemap: `https://bittopup.com/goods-sitemap-ar.xml` },
      { Sitemap: `https://bittopup.com/goods-sitemap-pt.xml` },
      { Sitemap: `https://bittopup.com/goods-sitemap-ru.xml` },
      { Sitemap: `https://bittopup.com/goods-sitemap-zh.xml` },
      { Sitemap: `https://bittopup.com/goods-sitemap-zh-hk.xml` },
    ],
  },

  devServer: {
    port: 3024,
  },

  image: {
    //   可以被nuxt-image处理的图片域名
    domains: ['bittopup.com', 'api.bittopup.com', 'bittopup.com', 'pic.bittopup.com'],
  },

  nitro: {
    compressPublicAssets: true,
    publicAssets: [
      {
        baseURL: 'public',
        dir: 'public',
        maxAge: 60 * 60 * 24 * 365, // 7 days
      },
    ],
  },

  app: {
    head: useNuxtHead(),
  },

  experimental: {
    //@ts-ignore
    inlineSSRStyles: false,
    writeEarlyHints: false,
    appManifest: true,
  },

  vue: {
    propsDestructure: true,
  },

  telemetry: {
    enabled: false,
  },

  runtimeConfig: {
    public: {
      DEFAULT_LOCALE,
      LANGUAGES,
      LANGUAGES_I18N,
      ...EnvConfig,
    },
  },

  $development: {
    //@ts-ignore
    routeRules: devRouteRules,
    image: {
      provider: 'myProvider',
      providers: {
        myProvider: {
          name: 'myProvider', // optional value to overrider provider name
          provider: '~/providers/my-provider.ts', // Path to custom provider
          options: {
            // ... provider options
            baseURL: 'https://pic.bittopup.com',
          },
        },
      },
    },
  },

  $production: {
    //@ts-ignore
    routeRules: prodRouteRules,
    image: {
      providers: {
        myProvider: {
          name: 'myProvider', // optional value to overrider provider name
          provider: '~/providers/my-provider.ts', // Path to custom provider
          options: {
            // ... provider options
            baseURL: 'https://site.com',
          },
        },
      },
    },
    // nitro: {
    //   storage: {
    //     cacheDB: {
    //       driver: 'mongodb',
    //       connectionString:
    //         'mongodb+srv://vijayniubi:wo131421@cluster0.cc2xgnf.mongodb.net/?retryWrites=true&w=majority',
    //     },
    //   },
    // },
  },

  routeRules: {},

  postcss: {
    plugins: {
      tailwindcss: {},
      autoprefixer: {},
    },
  },

  vite: {
    build: {
      assetsInlineLimit: 0,
    },
    esbuild: {
      drop: EnvConfig.IS_PROD ? ['console', 'debugger'] : [],
    },
  },

  hooks: {
    'build:manifest': (manifest) => {
      for (const key in manifest) {
        const file = manifest[key]
        if (file.assets) {
          file.assets = file.assets.filter(
            (asset: string) =>
              !asset.endsWith('.webp') && !asset.endsWith('.jpg') && !asset.endsWith('.svg') && !asset.endsWith('.png'),
          )
        }
      }
    },
  },
  //@ts-ignore
  compatibilityDate: '2024-09-03',
})
